﻿# -*- coding: UTF-8 -*-

import random
import os.path
import codecs
import random
from kivy import Logger


class DictionaryInfo():
    def __init__(self, file_name, description, words_count, enable_by_default):
        self.file_name = file_name
        self.description = description
        self.words_count = words_count
        self.enable_by_default = enable_by_default

    enabled_dictionaries = {}

    @staticmethod
    def parse_dictionaries_metadata():
        path_to_meta = os.path.join(os.path.dirname(__file__),
                                    '..', 'data', 'dictionaries.meta')
        dictionary_meta_file = codecs.open(path_to_meta, encoding='utf-8',
                                           mode='r')
        dicts_list = []
        for line in dictionary_meta_file:
            if (line.strip().startswith('#')):
                continue
            line = line.strip(' ')
            l = line.split(',')
            for i in range(len(l)):
                l[i] = l[i].strip(' ')
            if (l[3].lower().strip() == u'true'):
                dicts_list.append(DictionaryInfo(l[0], l[1], int(l[2]), True))
            else:
                dicts_list.append(DictionaryInfo(l[0], l[1], int(l[2]), False))

        return dicts_list
